/// @tags: Matrix
#include <cstdio>
#include <cstring>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

constexpr int MAXN = 53, P = 1e4;

int n, m;
int p[13];

inline int inc(int a, int b) {
  a += b;
  return a >= P ? a - P : a;
}

struct Matrix {
  int a[MAXN][MAXN];

  inline Matrix(int x = 0) {
    for (rint i = 0; i <= n; ++i)
      for (rint j = 0; j <= n; ++j) a[i][j] = i == j ? x : 0;
  }

  inline int *operator[](int index) { return a[index]; }
  inline const int *operator[](int index) const { return a[index]; }

  inline Matrix operator*(const Matrix &rhs) const {
    Matrix res;
    for (rint i = 0; i <= n; ++i)
      for (rint j = 0; j <= n; ++j)
        for (rint k = 0; k <= n; ++k) res[i][j] = inc(res[i][j], a[i][k] * rhs[k][j] % P);
    return res;
  }

  inline Matrix operator^(int exp) const {
    Matrix res(1), base(*this);
    for (; exp; exp >>= 1, base = base * base)
      if (exp & 1) res = res * base;
    return res;
  }
} a[13], T;

inline int main() {
  int nFish, start, end, k;
  cin >> n >> m >> start >> end >> k;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    T[x][y] = T[y][x] = 1;
  }
  for (rint i = 1; i <= 12; ++i) a[i] = T;
  cin >> nFish;
  for (int i = 1; i <= nFish; ++i) {
    int t;
    cin >> t;
    for (int j = 0; j < t; ++j) cin >> p[j];
    p[t] = p[0];
    for (int j = 1; j <= 12; ++j)
      for (int h = 0; h < n; ++h) a[j][h][p[(j - 1) % t + 1]] = 0;
  }
  a[0] = Matrix(1);
  for (int i = 1; i <= 12; ++i) a[0] = a[0] * a[i];
  Matrix ans = (a[0] ^ (k / 12));
  for (int i = 1; i <= k % 12; ++i) ans = ans * a[i];
  cout << ans[start][end];
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P2579 [ZJOI2005] 沼泽鳄鱼.in", "r", stdin);
  freopen("P2579 [ZJOI2005] 沼泽鳄鱼.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
